package com.igz.remote.service.rest.impl;


import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import com.google.appengine.api.channel.ChannelMessage;
import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.sun.jersey.api.view.Viewable;



@Path("/remote/")
public class RemoteResource {
		
	@GET
	@Produces("text/html")
	@Path("/{sessionId}")
	public Viewable getRemote(@PathParam("sessionId") String p_sessionId) {
		Map<String, String> model = new HashMap<String, String>();
		model.put("sessionId", p_sessionId);
		return  new Viewable("/remote_control", model);
	}
	
	@POST
	@Path("/update/")
	public void UpdatePos(@Context HttpServletRequest req,
			@FormParam("sessionId") String  p_sessionId,
			@FormParam("x") Integer  p_x,
			@FormParam("y") Integer  p_y
			){
		System.out.println(p_x+"_"+p_y+"_"+p_sessionId+"_");
		ChannelService channelService = ChannelServiceFactory.getChannelService();
	    channelService.sendMessage(new ChannelMessage(p_sessionId, p_x+","+p_y));
	}
}
